<?php
declare (strict_types=1);

namespace app\admin\service\system;

use app\model\system\SystemAdmin;
use app\model\system\SystemGroup;
use app\model\system\SystemRule;

class GroupService
{
    /**
     * 获取系统用户
     * @param array $where
     * @return \think\Paginator
     * @throws \Exception
     * @author dgc<453342213@qq.com>
     */
    public function getList($where = [])
    {
        //$where[] = ['status', '=', 1];
        //超级管理员 返回所有菜单
        /*if ($user['group_id'] != 1) {
            //$where[]=['id','in',$user['']]
        }*/
        $list = (new SystemGroup())->getList($where, "id,title,status,rules");
        return $list;
    }

    /**
     * 获取数 rule
     * @return array
     * @author dgc<453342213@qq.com>
     */
    public function  getRule(){
        $list =  $list = (new SystemRule())->getList([],'id,name as label,pid');
        $list = listToTree($list, 0, 'pid', 'children', 'id');
        return $list;
    }

    /**
     * 操作
     * @param array $where
     * @return \think\Collection
     * @throws \Exception
     * @author dgc<453342213@qq.com>
     */
    public function saves($param = [], $id)
    {
        $where = [];
        if ($id > 0) {
            $where['id'] = $id;
        }
        $model=new SystemGroup();
        $info = $model->where($where)->save($param);
        return $model;
    }
}
